Corridor items profile creator
Description
- This is a custom interactive tool for creating profile at constant elevation.
- The user is prompted to select a horizontal alignment upon which to create a vertical alignment. Then the user is prompted to input a constant elevation and select a feature definition.
- Then a vertical alignment with feature definition is created and activated.
- The CorridorItemsProfileCreator class extends DgnElementSetTool which handles different events to interact with UI, the CorridorItemsProfileCreator class overrides the events here in this tool.
Remarks
-
This sample code is a part of ManagedSDKExample which you get with SDK installation under "examples" section in SDK installation directory.
-
If you encounter any error while using DgnElementSetTool class, make sure to add a reference to Bentley.DgnDisplayNet.dll by selecting Project > Add Reference or change the projects .csproj file to add reference to this dll .
-
The default dll location will be "C:\Program Files\Bentley\OpenRoads Designer CE 10.11\OpenRoadsDesigner\Bentley.DgnDisplayNet.dll".
Source Code
//Required References
using Bentley.DgnPlatformNET;
using Bentley.DgnPlatformNET.Elements;
using Bentley.GeometryNET;
using Bentley.CifNET.LinearGeometry;
using BCGMSDK = Bentley.CifNET.GeometryModel.SDK;
using Bentley.CifNET.SDK.Edit;
using Bentley.CifNET.Formatting;
using System.Collections.Generic;
namespace ManagedSDKExample.Examples
{
class CorridorItemsProfileCreator : DgnElementSetTool
{
internal static DgnModel m_activeModel = Bentley.MstnPlatformNET.Session.Instance.GetActiveDgnModel();
internal static ModelInfo info = m_activeModel.GetModelInfo();
private double UOR_TO_MASTER = 1.0 / info.UorPerMeter;
internal static double m_defaultUnitsToMeters = FormatSettingsConstants.GetMasterUnitsToMeters();
private double METER_TO_MASTER = 1.0 / m_defaultUnitsToMeters;
private double mHeigh = 0.0;
private string mFeatureName = null;
/*----------------------------------------------------------------------------------------------**/
/* Write Function | The user is prompted to select a horizontal alignment upon which to create a
* vertical alignment. Then the user is prompted to input a constant elevation and
* select a feature definition. Then a vertical alignment with feature definition
* is created and activated.
/*--------------+---------------+---------------+---------------+---------------+----------------*/
internal void CreateProfile(Bentley.DgnPlatformNET.Elements.Element element)
{
if (element == null)
return;
ConsensusConnectionEdit con = ConsensusConnectionEdit.GetActive();
//Bentley.CifNET.SDK.Edit.ConsensusConnectionEdit con = Bentley.CifNET.SDK.Edit.ConsensusConnectionEdit.GetActive();
BCGMSDK.Alignment alignment = BCGMSDK.Alignment.CreateFromElement(con, element);
con.StartTransientMode();
ProfileLine profileLine = new ProfileLine(DPoint3d.FromXYZ(0, mHeigh, 0), DPoint3d.FromXYZ(alignment.LinearGeometry.Length, mHeigh, 0));
// create profile and active the profile
var profile = alignment.CreateProfileByProfileElement(profileLine, true, false);
profile.SetFeatureDefinition(mFeatureName, null);
con.PersistTransients();
}
protected override void OnPostInstall()
{
base.BeginPickElements();
Bentley.DgnPlatformNET.AccuSnap.LocateEnabled = true;
Bentley.DgnPlatformNET.AccuSnap.SnapEnabled = true;
base.OnPostInstall();
NotificationManager.OutputPrompt("Select a horizontal alignment.");
}
protected override bool OnDataButton(Bentley.DgnPlatformNET.DgnButtonEvent ev)
{
HitPath hitPath = DoLocate(ev, true, 1);
if (hitPath == null)
return false;
Bentley.DgnPlatformNET.Elements.Element selectedElement = hitPath.GetHeadElement();
if (selectedElement != null)
{
Bentley.CifNET.SDK.Edit.ConsensusConnectionEdit con = Bentley.CifNET.SDK.Edit.ConsensusConnectionEdit.GetActive();
BCGMSDK.Alignment alignment = BCGMSDK.Alignment.CreateFromElement(con, selectedElement);
if (alignment == null)
return true;
mHeigh = 200;
mHeigh *= METER_TO_MASTER;
List<string> featureNames = new List<string>();
Bentley.CifNET.GeometryModel.SDK.Edit.FeatureDefinitionManager fdm = Bentley.CifNET.GeometryModel.SDK.Edit.FeatureDefinitionManager.Instance;
featureNames.AddRange(fdm.GetFeatureDefinitions(Bentley.CifNET.SDK.Edit.ConsensusConnectionEdit.GetActive(), "Alignment"));
featureNames.Sort();
mFeatureName = featureNames[0];
CreateProfile(selectedElement);
NotificationManager.OutputPrompt("Command complete. Select a new horizontal alignment or right click to exit the command.");
}
return false; ;
}
protected override bool OnPostLocate(HitPath path, out string cantAcceptReason)
{
cantAcceptReason = string.Empty;
Element element = path.GetHeadElement();
DgnModel activeDgnModel = Bentley.MstnPlatformNET.Session.Instance.GetActiveDgnModel();
if (activeDgnModel.Is3d)
return false;
if (element.ElementType != MSElementType.Line && element.ElementType != MSElementType.LineString && element.ElementType != MSElementType.ComplexString)
{
cantAcceptReason = "This is not a civil element.";
return false;
}
return true;
}
//calls command on reset (right click)
protected override bool OnResetButton(DgnButtonEvent ev)
{
ExitTool();
return true;
}
protected override void OnRestartTool()
{
InstallNewInstance();
}
public override StatusInt OnElementModify(Element element)
{
return Bentley.DgnPlatformNET.StatusInt.Error;
}
public static void InstallNewInstance()
{
CorridorItemsProfileCreator cmd = new CorridorItemsProfileCreator();
cmd.InstallTool();
}
}
}